import datetime
import sys
from typing import *
from decimal import Decimal
from utils.exchange.binance import BinanceBase
from utils.strategy.loader import get_strategies, get_factor
from config import DEFAULT_TRADE_RULE
from collections import defaultdict


class GlobalVar:
    """
    公用数据
    """
    # 价格
    SPOT_PRICE: Dict[str, Decimal] = {}
    SWAP_PRICE: Dict[str, Decimal] = {}
    # 当前执行时间
    EXE_TIMESTAMP: int = 0
    START_TIME: Union[datetime.datetime, datetime.date] = None
    END_TIME: Union[datetime.datetime, datetime.date] = None

    ALL_STRATEGIES: Dict[str, str] = get_strategies()
    FACTORS: Dict[str, str] = get_factor()

    b = BinanceBase()
    SPOT_INFO: Dict[str, Any] = defaultdict(
        lambda: {"minQty": Decimal('0.00000001'), "minNotional": Decimal('5'),
                 "tickSize": Decimal('0.00000001')}) if DEFAULT_TRADE_RULE else b.spot_exchange_info
    SWAP_INFO: Dict[str, Any] = defaultdict(
        lambda: {"minQty": Decimal('0.00000001'), "minNotional": Decimal('5'),
                 "tickSize": Decimal('0.00000001')}) if DEFAULT_TRADE_RULE else b.swap_exchange_info
    BAK_STDOUT: TextIO = sys.stdout
    del b
